package com.yeban.javase.day16.state.waiting;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/30
 *
 * 无限等待状态 → 就绪状态
 */
public class WaitingAndRunnable {
    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();

        Thread t = new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println("线程等待中...");
                    lock.wait(); // WAITING
                    System.out.println("被唤醒继续执行");
                } catch (InterruptedException e) {}
            }
        });
        t.start();

        Thread.sleep(2000);
        synchronized (lock) {
            lock.notify(); // 唤醒线程
        }
    }
}
